import Vue from 'vue';
import Router from 'vue-router';

// import store from '../store';
import HomePage from '../components/home-page';
// import Login from '../components/login';
import AudioCall from '../components/audio-call';
import VideoCall from '../components/video-call';

Vue.use(Router);

export function createRouter () {
  const router = new Router({
    mode: 'hash',
    fallback: false,
    routes: [
      {
        path: "/",
        component: () => import("@/views/index"),
      },
      { path: "/login",
      component: () => import("@/views/login"),},
      { path: '/audio-call', component: AudioCall},
      { path: '/video-call', component: VideoCall},
      {
        path: "/admin",
        redirect:"/admin/orders",
        component: () => import("../views/admin"),
        children: [
          {path: "index", component:() => import('../views/admin/components/gly')},
          {path: "qiye", component:() => import('../views/admin/components/qiye')},
          {path: "orders",component: () => import("@/views/admin/components/orders")},
        ]
      },
      {
        path: "/u",
        redirect:"/u/index",
        component: () => import("../views/user"),
        children: [
          {path: "index", component:() => import('../views/user/components/index')},
          {path: "jianli", component:() => import('../views/user/components/jianli')},
          {path: "mianshi", component:() => import('../views/user/components/mianshi')},
          {path: "xiaoxi", component:() => import('../views/user/components/xiaoxi')},
          {path: "wode", component:() => import('../views/user/components/wode')},
        ]
      },
      {
        path: "/hr",
        redirect:"/hr/index",
        component: () => import("../views/hr"),
        children:[
          {path: "index", component:() => import('../views/hr/components/index')},
          {path: "jianli", component:() => import('../views/hr/components/jianli')},
          {path: "mianshi", component:() => import('../views/hr/components/mianshi')},
          {path: "zhiwei", component:() => import('../views/hr/components/zhiwei')},
          {path: "shoucang", component:() => import('../views/hr/components/shoucang')},
        ]
      },
    ]
  });
  // router.beforeEach((to, from, next) => {
  //   if (!store.state.isLogin) {
  //     if (to.fullPath !== '/login') {
  //       if (from.fullPath !== '/login') {
  //         next('/login');
  //       }
  //       return;
  //     }
  //   }
  //   next();
  // })
  return router;
}

const originalPush = Router.prototype.push
   Router.prototype.push = function push(location) {
   return originalPush.call(this, location).catch(err => err)
}